package com.toocms.jinjuhang.ui.mine.payment

import android.content.Intent
import android.os.Bundle
import com.qmuiteam.qmui.arch.QMUIFragment
import com.toocms.jinjuhang.R
import com.toocms.jinjuhang.BR
import com.toocms.jinjuhang.databinding.FgtPaymentBinding
import com.toocms.jinjuhang.ui.base.BaseFgt
import com.toocms.jinjuhang.ui.mine.payment.bank.code.CodeFgt
import com.toocms.tab.TooCMSApplication

class PaymentFgt : BaseFgt<FgtPaymentBinding, PaymentModel>() {
    override fun onFragmentCreated() {
        topBar.setTitle(R.string.str_select_payment_way)
    }

    override fun getLayoutResId() = R.layout.fgt_payment

    override fun getVariableId() = BR.paymentModel

    override fun viewObserver() {
        viewModel.showCodeEvent.observe(this) {
            val dialog = CodeFgt()
            val bundle = Bundle();
            bundle.putString("trade_no", it);
            bundle.putString("signid", viewModel.signid);
            bundle.putString("order_sn", viewModel.orderSn)
            dialog.arguments = bundle;
            dialog.show(childFragmentManager, "");
        }
    }

    override fun getViewModel() = PaymentModel(TooCMSApplication.getInstance(), arguments)

    override fun onFragmentResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (resultCode != QMUIFragment.RESULT_OK) return
        if (requestCode == 0x1) {
            viewModel.signid = data?.getStringExtra("signid")!!
            viewModel.card_no.set(data.getStringExtra("card_no"))
        }
    }
}